package bean;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import Uitls.LogUtil;

/**
 * Created by Administrator on 2016/7/15.
 * 获取当前网络的状态
 *  -1:没有网络 ，1:wifi 网络，2:wap网络，3:net网络
 */
public class Type {
    private static final int CMNET = 3 ;
    private static final int CMWAP = 2;
    private static final int WIFI =  1;

    public static int getAPNType(Context context) {
        int netType = -1;

        ConnectivityManager connMgr = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if(networkInfo==null) {
            return netType;
        }

        int type = networkInfo.getType();
        if(type==ConnectivityManager.TYPE_MOBILE) {
            LogUtil.d("mobile",networkInfo.getExtraInfo());

            if(networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
                netType = CMNET;
            } else {
                netType = CMWAP;
            }
        }else if(type==ConnectivityManager.TYPE_WIFI){
                netType = WIFI;
        }
        return netType;
    }

}
